import SwiftUI
import SwiftUIX

struct GradientBackground: View {
    @State private var isAnimating = false
    @State private var text: String = ""
    @State var isEditing: Bool = false
       @State var searchText: String = ""
    
    let gradient1 = LinearGradient(gradient: Gradient(colors: [.blue, .purple]), startPoint: .topLeading, endPoint: .bottomTrailing)
    let gradient2 = LinearGradient(gradient: Gradient(colors: [.red, .orange]), startPoint: .topLeading, endPoint: .bottomTrailing)

    var body: some View {
        ZStack {
            // 渐变背景动画
            (isAnimating ? gradient2 : gradient1)
                .edgesIgnoringSafeArea(.all)
                .animation(.easeInOut(duration: 5).repeatForever(autoreverses: true), value: isAnimating)
            
            VisualEffectBlurView(blurStyle: .systemMaterial)
                .edgesIgnoringSafeArea(.all)
            
            
            SearchBar("请输入搜索内容...", text: $searchText, isEditing: $isEditing)
                        .showsCancelButton(isEditing)
                        .onCancel { print("Canceled!") }
            

        }
        .onAppear {
            // 自动启动动画
            isAnimating = true
        }
    }
}

struct GradientBackground_Previews: PreviewProvider {
    static var previews: some View {
        GradientBackground()
    }
}
